<?php
declare (strict_types = 1);
namespace app;

use think\App;
use think\exception\HttpResponseException;
use think\Response;

class PublicController
{
    public function success_back($msg = '', $data = [], $count = 0, $code = 0, $header = [])
    {
        $result = [
            'code'  => $code,
            'msg'   => $msg,
            'count' => $count,
            'data'  => $data,
        ];
    
        $response = Response::create($result, 'json')->header($header);
        throw new HttpResponseException($response);
    }

    public function error_back($msg = '', $data = [], $count = 0, $code = 400, $header = [])
    {
        $result = [
            'code'  => $code,
            'msg'   => $msg,
            'count' => $count,
            'data'  => $data,
        ];
    
        $response = Response::create($result, 'json')->header($header);
        throw new HttpResponseException($response);
    }
}
